//
//  BlogFrame.m
//  QSBK
//
//  Created by Eric Wang on 4/20/15.
//  Copyright (c) 2015 Eric Wang. All rights reserved.
//

#import "BlogFrame.h"
#import "UIImageView+WebCache.h"

@implementation BlogFrame


-(void)setBlog:(Blog *)blog
{
 
    _blog = blog;
//    @property(nonatomic,assign)CGRect bgView;
    CGFloat bgViewX = 5;
    CGFloat bgViewY = 2.5;
    CGFloat bgViewW = ScreenW - 10;
    CGFloat bgViewH;
//    //touxiang
//    @property(nonatomic,assign)CGRect headImage;
    CGFloat headImageX = 5;
    CGFloat headImageY = 5;
    CGFloat headImageW = 40;
    CGFloat headImageH = 40;
    self.headImage = CGRectMake(headImageX, headImageY, headImageW, headImageH);
//    //name
//    @property(nonatomic,assign)CGRect nameLabel;
    CGFloat nameLabelX = headImageX + headImageW +20;
    CGFloat nameLabelY = headImageY + 12.5;
    CGFloat nameLabelW = 250;
    CGFloat nameLabelH = 20;
    self.nameLabel = CGRectMake(nameLabelX, nameLabelY, nameLabelW, nameLabelH);
    
    //    //contentLabel
    //    @property(nonatomic,assign)CGRect contentLabel;
    CGFloat contentLabelX = headImageX;
    CGFloat contentLabelY = headImageY+headImageH+5;
    CGFloat contentImageY;
    if(_blog.content == nil)
    {
        self.contentLabel = CGRectZero;
    }else
    {
        UIFont *fnt = [UIFont fontWithName:@"HelveticaNeue" size:15];
                CGRect ContentLabel = [_blog.content boundingRectWithSize:CGSizeMake(ScreenW-15, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObjectsAndKeys:fnt,NSFontAttributeName, nil] context:nil];
        self.contentLabel = CGRectMake(contentLabelX, contentLabelY, ContentLabel.size.width, ContentLabel.size.height);
    }
    contentImageY = contentLabelY+self.contentLabel.size.height+5;
    //    //contentImage
    //    @property(nonatomic,assign)CGRect contentImage;
    CGFloat contentImageX = headImageX;
    CGFloat picViewX = contentImageX;
    CGFloat picViewY = contentImageY;
    CGFloat upLabelY;
    if(_blog.pic_url == nil)
    {
        
        if(_blog.image == nil)
        {
            self.contentImage = CGRectZero;
            upLabelY = contentImageY;
        }
        else{
            CGFloat imageW = [_blog.image_width floatValue];
            CGFloat imageH = [_blog.image_height floatValue];
            
            CGFloat scale = (bgViewW-10)/imageW;
            self.contentImage = CGRectMake(contentImageX , contentImageY, imageW*scale,imageH*scale);
            upLabelY = contentImageY+imageH*scale+5;
        }
        self.picView = CGRectZero;
    }else{
        self.contentImage = CGRectZero;
        CGFloat picW = [[_blog.pic_size objectAtIndex:0] intValue];
        CGFloat picH = [[_blog.pic_size objectAtIndex:1] intValue];
        
        CGFloat picScale = (bgViewW-10)/picW;
        
        CGFloat X = (picW*picScale -50)/2;
        CGFloat Y = (picH*picScale-50)/2;
        self.playButton = CGRectMake(X, Y, 50, 50);
        self.picView = CGRectMake(picViewX, picViewY, picW*picScale, picH*picScale);
        upLabelY = picViewY + picH*picScale+5;
    }
    

//    @property(nonatomic,assign)CGRect upLabel;
    
    CGFloat upLabelX = headImageX;
    self.upLabel = CGRectMake(upLabelX, upLabelY, 100, 25);
//    //commentLabel
//    @property(nonatomic,assign)CGRect commentLabel;
    CGFloat commentLabelX = upLabelX + 105;
    CGFloat commentLabelY = upLabelY;
    CGFloat commentLabelW = 100;
    CGFloat commentLabelH = 25;
    self.commentLabel = CGRectMake(commentLabelX, commentLabelY, commentLabelW, commentLabelH);
//    //up
//    @property(nonatomic,assign)CGRect upButton;
//    //down
    CGFloat upButtonX = upLabelX;
    CGFloat upButtonY = upLabelY+30;
    CGFloat upButtonW = 60;
    CGFloat upButtonH = 60;
    self.upButton = CGRectMake(upButtonX, upButtonY, upButtonW, upButtonH);
//    @property(nonatomic,assign)CGRect downButton;
//    //commentButton
    CGFloat downButtonX = upButtonX+upButtonW+5;
    CGFloat downButtonY = upButtonY;
    CGFloat downButtonW = 60;
    CGFloat downButtonH = 60;
    self.downButton = CGRectMake(downButtonX, downButtonY, downButtonW, downButtonH);
//    @property(nonatomic,assign)CGRect commentButton;
//    //more
    CGFloat commentButtonX = downButtonX+downButtonW+5;
    CGFloat commentButtonY = downButtonY;
    CGFloat commentButtonW = 60;
    CGFloat commentButtonH = 60;
    self.commentButton = CGRectMake(commentButtonX, commentButtonY, commentButtonW, commentButtonH);
//    @property(nonatomic,assign)CGRect moreButton;
//
    CGFloat moreButtonX = ScreenW-80;
    CGFloat moreButtonY = commentButtonY;
    CGFloat moreButtonW = 60;
    CGFloat moreButtonH = 60;
    self.moreButton = CGRectMake(moreButtonX, moreButtonY, moreButtonW, moreButtonH);
    
//    @property(nonatomic,assign)CGFloat cellHeight;
    
    bgViewH = moreButtonY+moreButtonH+10;
    
    self.bgView = CGRectMake(bgViewX, bgViewY, bgViewW, bgViewH);
    self.cellHeight = bgViewH+2.5;
}
@end
